<template>
  <div class="common-layout">
    <!-- 头部 -->
    <el-header class="header">
      <div class="header-content">
        <el-icon class="logo-icon">
          <Car />
        </el-icon>
        <h2 class="title">小鹏打车——管理中心</h2>
      </div>
<!--      <el-button @click="toggleSidebar" class="menu-button">-->
<!--        <el-icon v-if="!isSidebarOpen">-->
<!--          <Menu />-->
<!--        </el-icon>-->
<!--        <el-icon v-else>-->
<!--          <Close />-->
<!--        </el-icon>-->
<!--        <span class="button-text">{{ isSidebarOpen ? '关闭菜单' : '打开菜单' }}</span>-->
<!--      </el-button>-->
    </el-header>

    <!-- 主体内容 -->
    <div class="main-container">
      <!-- 左侧菜单栏 -->
      <el-aside :class="['sidebar', isSidebarOpen ? 'open' : 'closed']">
        <div class="sidebar-header">
          <p class="sidebar-title">管理菜单</p>
        </div>
        <nav class="menu">
          <router-link v-for="item in menuItems" :key="item.path" :to="item.path" class="menu-item"
            active-class="active">
            <el-icon class="menu-icon">
              <component :is="item.icon"></component>
            </el-icon>
            <span class="menu-text">{{ item.title }}</span>
          </router-link>
        </nav>
        <div class="sidebar-footer">
          <p class="footer-text">管理系统 v1.0.0</p>
        </div>
      </el-aside>

      <!-- 右侧内容区域 -->
      <el-main :class="['content', { 'with-sidebar': isSidebarOpen }]">
        <router-view />
      </el-main>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
// import { Car, Menu, Close, User, Truck, People } from '@element-plus/icons-vue';

const isSidebarOpen = ref(true); // 默认展开侧边栏

const toggleSidebar = () => {
  isSidebarOpen.value = !isSidebarOpen.value;
};

const menuItems = [
  { title: '用户表', path: '/user' },
  { title: '汽车表', path: '/car' },
  { title: '司机表', path: '/driver' },
  { title: '价格表', path: '/price' },
  { title: '订单表', path: '/order' },

];
</script>

<style scoped>
/* 基础样式 */
.common-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f5f7fa;
}

/* 头部样式 */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 0 20px;
  height: 64px;
  z-index: 10;
}

.header-content {
  display: flex;
  align-items: center;
}

.logo-icon {
  color: #409eff;
  font-size: 24px;
  margin-right: 10px;
}

.title {
  font-size: 20px;
  font-weight: bold;
  color: #333333;
}

.menu-button {
  display: flex;
  align-items: center;
  background-color: #409eff;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.menu-button:hover {
  background-color: #66b1ff;
}

.button-text {
  margin-left: 5px;
}

/* 主体内容样式 */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* 侧边栏样式 */
.sidebar {
  width: 20%;
  background-color: #ffffff;
  border-right: 1px solid #e6e6e6;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease-in-out;
  z-index: 20;
  height: calc(100vh - 64px);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar.closed {
  transform: translateX(-100%);
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #e6e6e6;
}

.sidebar-title {
  font-size: 14px;
  color: #909399;
  text-transform: uppercase;
  margin: 0;
}

.menu {
  padding: 16px 0;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 12px 24px;
  color: #606266;
  text-decoration: none;
  transition: all 0.3s ease;
}

.menu-item:hover {
  background-color: #ecf5ff;
  color: #409eff;
}

.menu-icon {
  margin-right: 12px;
  font-size: 18px;
}

.menu-text {
  font-size: 14px;
}

.menu-item.active {
  background-color: #ecf5ff;
  color: #409eff;
  border-left: 3px solid #409eff;
}

.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  border-top: 1px solid #e6e6e6;
  background: linear-gradient(to top, #f5f7fa, transparent);
}

.footer-text {
  font-size: 12px;
  color: #909399;
  text-align: center;
  margin: 0;
}

/* 内容区域样式 */
.content {
  flex: 1;
  padding: 20px;
  transition: margin-left 0.3s ease-in-out;
}

.content.with-sidebar {
  /*margin-left: 20%;*/
}

/* 响应式调整 */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    height: calc(100vh - 64px);
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    width: 70%;
  }

  .sidebar.closed {
    transform: translateX(-100%);
    width: 70%;
  }

  .content {
    margin-left: 0;
  }
}
</style>
